package com.jinxin.platform.cdqzsqacs.service.impl;

import com.jinxin.platform.base.common.pojo.JsonResult;
import com.jinxin.platform.cdqzsqacs.bean.CdqzsqacsOpenRecord;
import com.jinxin.platform.cdqzsqacs.mapper.CdqzsqacsOpenRecordMapper;
import com.jinxin.platform.cdqzsqacs.service.IQzsqAcsRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.HashMap;
import java.util.List;

/**
 * All rights Reserved, Designed By www.beonelot.com
 *
 * @version: V1.0
 * @Copyright: www.beonelot.com Inc. All rights reserved.
 * @Description：
 * @Date: 2021-01-30
 * @Author: Lingnan
 **/
@Service
public class QzsqAcsRecordServiceImpl implements IQzsqAcsRecordService {
    @Autowired
    private CdqzsqacsOpenRecordMapper recordMapper;

    @Override
    public List<CdqzsqacsOpenRecord> list(HashMap param) {
        return recordMapper.list(param);
    }

    @Override
    public List<CdqzsqacsOpenRecord> listPage(HashMap param) {
        return recordMapper.listPage(param);
    }

    @Override
    public int listPageCount(HashMap param) {
        return recordMapper.listPageCount(param);
    }

    @Override
    public JsonResult delete(String id) {
        if(StringUtils.isEmpty(id)){
            return JsonResult.error("门禁记录不存在");
        }
        int result = recordMapper.deleteByKey(id);
        if(result > 0){
            return JsonResult.ok("删除成功","");
        }
        return JsonResult.error("删除失败");
    }

    @Override
    public JsonResult saveOrUpdate(CdqzsqacsOpenRecord record) {
        if (record == null){
            return JsonResult.error("参数错误，操作失败");
        }
        String id = record.getId();
        int count;
        String msg = "";
        if(StringUtils.isEmpty(id)){
            count = recordMapper.insert(record);
            msg = "新增成功";
        }else {
            count = recordMapper.updateByKey(record);
            msg = "更新成功";
        }
        if(count > 0){
            return JsonResult.ok(msg,"");
        }else {
            return JsonResult.error("操作失败，请重试");
        }
    }
}
